//初始化展示
$(document).ready(function () {
    $('#FumMian_num').DataTable({
        // fixedHeader: true
    });
    var request_parameters = {type: "get_sentive_user"}   //默认传值

    $.ajax({
        type: "post",
        url: "http://127.0.0.1:9998/analysis/get_sensitive_user",
        data: request_parameters,
        async: true,
        datatype: "Json",
        success: function (rsp) {
            optionJson = rsp.data;
            console.log(optionJson.data);

            $("#FumMian_num").dataTable().fnDestroy();//还原初始化
            $('#FumMian_num').DataTable({
                bFilter: false,
                "lengthMenu": [15, 10, 5],
                bStateSave: true,//翻页时保存状态
                data: optionJson.data,

                //设置列数据
                columns: [

                    {
                        "data": 'phoneNum',
                        "width": '60',
                        "render": function (data, type, row, meta) {
                            return data = '<a  href="#"> <p onclick = "search(' + data + ')">' + data + '</p> </a>';
                        }

                    },
                    {
                        "data": 'inclination',
                        "width": '40',
                    },
                ],
                //设置排序
                "order": [[1, 'asc']],
                //设置语言
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项搜索结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 条数据",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "未搜索到数据",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                },
            });
        }
    });
});


function search(data) {
    console.log("search方法");
    // 词云图JS
    var worldCloudcharts = echarts.init(document.getElementById('MinGan_ciyun'));
    var worldCloudoption = {
        tooltip: {
            show: true
        },
        series: [{
            name: '敏感词语',
            type: 'wordCloud',
            sizeRange: [6, 28],
            rotationRange: [-45, 90],
            drawOutOfBound: true,
            textPadding: 0,
            autoSize: {
                enable: true,
                minSize: 6
            },
            textStyle: {
                normal: {
                    color: function () {
                        return 'rgb(' + [
                            Math.round(Math.random() * 160),
                            Math.round(Math.random() * 160),
                            Math.round(Math.random() * 160)
                        ].join(',') + ')';
                    }
                },
                emphasis: {
                    shadowBlur: 10,
                    shadowColor: '#333'
                }
            },
            data: []
        }]
    };


    //进度条绘制
    window.onload = function () {
        (function (obj) {
            obj.win = {
                /**
                 * 环形进度条
                 * @param el：DOM对象
                 * @param val:数值
                 * @param bg:背景颜色
                 * @param color:环颜色
                 * @param textColor：数字颜色
                 * @param fontSize：数字字体大小
                 * @param size:环宽度
                 * @param r:环内半径
                 * @param time:动画时间
                 * @param easing:动画类型:
                 *  'linear'
                 *  '<' or 'easeIn' or 'ease-in'
                 *  '>' or 'easeOut' or 'ease-out'
                 *  '<>' or 'easeInOut' or 'ease-in-out'
                 *  'backIn'or 'back-in'
                 *  'backOut' or 'back-out'
                 *  'elastic'
                 *  'bounce'
                 */
                loopFun: function (el, val, bg, color, textColor, fontSize, size, r, time, easing) {
                    var si = r + size / 2;
                    var xy = r + size;
                    if (val < 0 || val > 100) {
                        return alert('请输入0~100之间的数')
                    }
                    var paper = Raphael(el, (r + size) * 2, (r + size) * 2);
                    paper.circle(xy, xy, r).attr({
                        'stroke-width': size,
                        stroke: bg
                    });
                    paper.customAttributes.arc = function (val) {
                        var v = 360 * val / 100,
                            s = -180,
                            e = s + v,
                            x = xy,
                            y = xy,
                            rad = Math.PI / 180,
                            x1 = x + r * Math.sin(-s * rad),
                            y1 = y + r * Math.cos(-s * rad),
                            x2 = x + r * Math.sin(-e * rad),
                            y2 = y + r * Math.cos(-e * rad),
                            path = [
                                ['M', x1, y1],
                                ['A', r, r, 0, +(e - s > 180), 1, x2, y2]
                            ];
                        return {
                            path: path
                        };
                    };
                    var an = paper.path().attr({
                        'stroke-width': size,
                        stroke: color,
                        arc: 0.01
                    });
                    an.animate({
                        stroke: color,
                        arc: val
                    }, time, easing);
                    setTimeout(function () {
                        if (val == 100) {
                            paper.circle(xy, xy, r).attr({
                                'stroke-width': size,
                                stroke: color
                            });
                        }
                    }, time);
                    paper.customAttributes.txt = function (val) {
                        return {
                            text: Math.floor(val * 100) / 100 + '%'
                        }
                    };
                    var l = paper.text(xy, xy).attr({
                        txt: 0,
                        'fill': textColor,
                        'font-size': fontSize,
                        'font-weight': 700
                    });
                    l.animate({
                        txt: val
                    }, time);
                },

            };
        })(window);

    }
    //var request_parameters = {type: "get_sentive_user"}   //默认传值
    var request_parameters = {type: "get_this_phone_num_info", phone_num: data}    //data 是<a>这里面的数值</a>
    //ajax程序      写在了最后
    $.ajax({
        url: "http://127.0.0.1:9998/analysis/get_this_phone_num_info",
        type: "POST",
        time: '3000',
        dataType: "json",
        data: request_parameters,
        success: function (response) {

            rsp = response.data;

            // 词云图JS 通过它的post >>写>> 【进度条】JS
            var data_value = parseFloat(rsp.info.inclination) //转小数型
            data_value_fin = data_value.toFixed(2);
            console.log(data_value_fin);
            var Zheng = 0;
            var Fu = 0;
            if (data_value_fin > 0) {
                Zheng = data_value_fin;
                Fu = 0;
            }
            if (data_value_fin < 0) {
                Zheng = 0;
                Fu = data_value_fin;
            }
            if (data_value_fin == 0) {
                Zheng = 0;
                Fu = 0;
            }

            console.log(Zheng);
            console.log(Fu);
            var get_Zheng_fin = 100 * Zheng;            //为了图片显示做的 数据处理
            var get_Fu_fin = 100 * (Math.abs(Fu));      //为了图片显示做的 数据处理
            console.log(get_Zheng_fin);
            console.log(get_Fu_fin);
            $('.div1').html("");
            $('.div2').html("");

            // 分级
            if (get_Zheng_fin >= 0) {
                document.getElementById('YuJingFenJiBG').style.background = "#00A0E9";
                document.getElementById('MinGan_JinDuTiao_FenJitxt').innerHTML = "良好"

            }
            if (get_Fu_fin > 0 && get_Fu_fin <= 10) {
                document.getElementById('YuJingFenJiBG').style.background = "#FFD700";
                document.getElementById('MinGan_JinDuTiao_FenJitxt').innerHTML = "低风险"
            }
            if (get_Fu_fin > 10 && get_Fu_fin <= 30) {
                document.getElementById('YuJingFenJiBG').style.background = "#FF8247";
                document.getElementById('MinGan_JinDuTiao_FenJitxt').innerHTML = "高风险"
            }
            if (get_Fu_fin > 30 && get_Fu_fin <= 100) {
                document.getElementById('YuJingFenJiBG').style.background = "#B22222";
                document.getElementById('MinGan_JinDuTiao_FenJitxt').innerHTML = "危急"
            }


            win.loopFun($('.div1')[0], get_Fu_fin, '#ccc', '#333', '#333', '20px', 20, 60, 1000, 'bounce');
            win.loopFun($('.div2')[0], get_Zheng_fin, '#ccc', '#00A0E9', '#00A0E9', '20px', 20, 60, 1000, 'back-out');


            // 词云图JS 通过它的post >>写>> 【常用联系人】JS
            var str = ""
            var j = 1
            data_usucontacts = rsp.frequentContacts      //都拿来
            for (var one in data_usucontacts) {                         //遍历一下
                str = str + "<tr><td>" + j + ":&nbsp;&nbsp;</td>" + "<td>"
                    + data_usucontacts[one].phoneNum2 + "</td>" + "<td> &nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;" + data_usucontacts[one].relation + "</td></tr>" //选择要哪个
                j = j + 1;
            }
            // document.getElementById('table_pai').innerHTML = ""
            document.getElementById('MinGan_UsualContact').innerHTML = ""   //清空 #table_pai div
            var table = $('#MinGan_UsualContact').append(str)

            // 词云图JS实现
            //var data_name = []
            var JsonList = []
            if (response.code == 1) {
                data_name = rsp.info.sensitiveWord.split(",")    //都拿来
                for (var one in data_name) {                   //一个一个遍历
                    var word_name = {}
                    var value = Math.random() * 1
                    word_name['name'] = data_name[one]
                    word_name['value'] = value
                    JsonList.push(word_name)
                }
                console.log(JsonList)
                worldCloudoption.series[0].data = JsonList;
                worldCloudcharts.setOption(worldCloudoption);
            }
        },
        error: function (e) {
            /* Act on the event */
            console.log(e);
        }
    });
}

// //前端将群体关键人号码传给后台，后台返回关键人信息
function Go_key_user(phone_num) {
    let clickPhone = phone_num;

}

